package com.lzh.runke.core.web_base.helper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Description: Date - LocalDate - LocalDateTime 帮助类
 * @Author: LiuZiHao
 * @Date: 2022/5/24 18:02
 */
public class DateHelper {

    protected final static String ZONE_ID = "PRC";

    public static Date asDate(LocalDate localDate) {
        if (null == localDate) {
            return null;
        }
        return Date.from(localDate.atStartOfDay().atZone(ZoneId.of(ZONE_ID)).toInstant());
    }

    public static Date asDate(LocalDateTime localDateTime) {
        if (null == localDateTime) {
            return null;
        }
        return Date.from(localDateTime.atZone(ZoneId.of(ZONE_ID)).toInstant());
    }

    public static LocalDate asLocalDate(Date date) {
        if (null == date) {
            return null;
        }
        return date.toInstant().atZone(ZoneId.of(ZONE_ID)).toLocalDate();
    }

    public static LocalDateTime asLocalDateTime(Date date) {
        if (null == date) {
            return null;
        }
        return date.toInstant().atZone(ZoneId.of(ZONE_ID)).toLocalDateTime();
    }
}
